package com.tianji.aigc.config.mvc;

import com.tianji.auth.common.constants.JwtConstants;
import com.tianji.common.utils.UserContext;
import feign.RequestInterceptor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class FeignConfig {

    //Feign 提供的请求拦截器接口，用于在 Feign 发起请求前对请求进行自定义修改。
    @Bean
    public RequestInterceptor userInfoRequestInterceptor() {
        return template -> {
            Long userId = UserContext.getUser();
            if (userId != null) {
                template.header(JwtConstants.USER_HEADER, userId.toString());
            }
        };
    }
}
